package cn.tangsihai.mq._05_topic;

import com.rabbitmq.client.*;

public class Producer {
    // 交换机名
    public static final String EXCHANGE_TOPIC_NAME = "EXCHANGE_TOPIC_NAME11";
    public static void main(String[] args) throws Exception{
        // 创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("115.159.88.63");
        Connection connection = factory.newConnection();
        // 创建通道
        Channel channel = connection.createChannel();
        // 创建交换机
        channel.exchangeDeclare(EXCHANGE_TOPIC_NAME, BuiltinExchangeType.TOPIC, true); // 是否持久化
        // 发送消息
        // MessageProperties.PERSISTENT_TEXT_PLAIN：发送消息持久化
        channel.basicPublish(EXCHANGE_TOPIC_NAME, "info.fk.info.tgbd", MessageProperties.PERSISTENT_TEXT_PLAIN, "汤思海发送info消息".getBytes());
        channel.basicPublish(EXCHANGE_TOPIC_NAME, "error.dfs", MessageProperties.PERSISTENT_TEXT_PLAIN, "汤思海发送error消息".getBytes());
        System.out.println("消息发送成功");
    }
}
